// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import store from './vuex/index'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
//导入fontawesome
import { library } from '@fortawesome/fontawesome-svg-core';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
//引入图标
import {
  faEdit,//编辑图标
  faTrashAlt
} from '@fortawesome/free-regular-svg-icons';
library.add(
  faEdit,
  faTrashAlt
);
//注册Font Awesome组件
Vue.component('font-awesome-icon', FontAwesomeIcon);

Vue.use(ElementUI)
Vue.config.productionTip = false

let http = axios.create();

//请求拦截器
http.interceptors.request.use(
  config => {
    //从sessionstorage中获取token、refreshtoken携带上
    let token = window.sessionStorage.getItem("token");
    let refreshtoken = window.sessionStorage.getItem("refreshtoken");
    if(token){
      config.headers.authorization = token;
    }
    if(refreshtoken){
      config.headers.refreshtoken = refreshtoken;
    }
    return config;
  }
);
//响应拦截
http.interceptors.response.use(
  response =>{
    //获取token
    let token = response.headers.authorization;
    let refreshtoken = response.headers.refreshtoken;
    //
    if(token){
      window.sessionStorage.setItem("token",token);
    }
    if(refreshtoken){
      window.sessionStorage.setItem("refreshtoken",refreshtoken);
    }
    //
    return response;
  }
);


Vue.prototype.axios = http;
Vue.prototype.baseUrl = "http://192.168.8.161:8002/"
Vue.prototype.$store = store;


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
